package org.jaaksi.kottlindemo

import android.app.Application
import android.content.Context
import dagger.hilt.android.HiltAndroidApp
import leakcanary.AppWatcher
import libcore.eventbus.EventBusInitializer
import libcore.kotpref.KotPref
import libcore.util.appContext
import org.greenrobot.greendao.query.QueryBuilder
import org.jaaksi.kottlindemo.LibConfig.Companion.applicationContext
import org.jaaksi.kottlindemo.home.AppLifecycleCallbacks
import org.jaaksi.kottlindemo.home.MyLifecycleObserver
import timber.log.Timber

@HiltAndroidApp
class TheApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        EventBusInitializer.init(this)
        QueryBuilder.LOG_SQL = true
        QueryBuilder.LOG_VALUES = true
        KotPref.init(applicationContext)
        LibConfig.applicationContext = this
        appContext = this
        libcore.config.LibConfig.init(this, object : libcore.config.LibConfig.Callback {
            override fun isDebug(): Boolean {
                return BuildConfig.DEBUG
            }

            override fun getBaseUrl(): String {
                return ""
            }
        })
        if (BuildConfig.DEBUG) {
            Timber.plant(Timber.DebugTree())
        } else {
//            Timber.plant(CrashReportingTree());
        }
        registerActivityLifecycleCallbacks(AppLifecycleCallbacks)

        MyLifecycleObserver.initLifecycle()

        // 日志会打印协程名
        System.setProperty(
            kotlinx.coroutines.DEBUG_PROPERTY_NAME,
            kotlinx.coroutines.DEBUG_PROPERTY_VALUE_ON
        )
    }



}